package com.wanggan.rmi.util;

import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

/**
 * @author wanggan
 */
public class RegistryUtil {
    private static Registry registry = null;
    static {
        
        try {
            registry = LocateRegistry.getRegistry();//从本地拿
            registry.list();
            System.out.println("Register the exist server!");//说明已经有RMIService了不需要在创建一个新的了
        } catch (RemoteException re) {
            try {
                int port = 1099;//RMIService监听的端口，自己指定！
                registry = LocateRegistry.createRegistry(port);//在本地创建
                System.out.println("Create Registry Server!"); //创建了一个新的RMIService
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    
    public static Registry getRegistry(){
        return registry;
    }
    
    
}
